﻿<r:RibbonWindow
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:r="clr-namespace:Microsoft.Windows.Controls.Ribbon;assembly=RibbonControlsLibrary"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:me="clr-namespace:Moon"
    x:Class="Moon.Window1"
    Title="Moon" Loaded="Window_Loaded" mc:Ignorable="d"
    WindowStartupLocation="CenterScreen"
    FontFamily="Arial" MinWidth="500" MinHeight="500" Width="500" Height="500"
    Icon="images/Logo.png">
    <r:RibbonWindow.Background>
         <ImageBrush Stretch="Fill" 
                    ImageSource="images/Wave.jpg" />
    </r:RibbonWindow.Background>

    <DockPanel>
        <DockPanel.Resources>
            
            
            
            <ResourceDictionary>
                <r:RibbonCommand x:Key="SearchByTagCommand"
                                Executed="SearchByTag_Executed"
                                LabelTitle="按标签"
                                ToolTipTitle="按所选标签搜索"
                                ToolTipDescription="按所选标签搜索，相关的资源和标签将重新填充;在标签列表处于焦点时按Enter也可"
                                SmallImageSource="images/Clear.png"
                                LargeImageSource="images/Clear.png" />

                <r:RibbonCommand x:Key="SearchByResourceCommand"
                                Executed="SearchByResource_Executed"
                                LabelTitle="按资源"
                                ToolTipTitle="按所选资源搜索"
                                ToolTipDescription="按所选资源搜索，相关的资源和标签将重新填充;在标签列表处于焦点时按Enter也可"
                                SmallImageSource="images/Copy.png"
                                LargeImageSource="images/Copy.png" />

                <r:RibbonCommand x:Key="OpenResourceCommand"
                                 Executed="OpenResource_Executed"
                                 LabelTitle="打开"
                                 ToolTipTitle="打开所选资源"
                                 ToolTipDescription="按照所选文件的路径，打开或运行所选资源."
                                 SmallImageSource="images/Paste.png"
                                 LargeImageSource="images/Paste.png" />

                <r:RibbonCommand x:Key="CreateRelationCommand"
                                 Executed="RelationCreated_Excuted"
                                 LabelTitle="创建联系"
                                 ToolTipTitle="将所选标签贴在所选资源上"
                                 ToolTipDescription="在所选标签和所选资源自检建立联系，使其在所搜时可通过此联系找到对方."
                                 SmallImageSource="images/Help.png"
                                 LargeImageSource="images/Help.png" />
                
                <r:RibbonCommand x:Key="goBackCommand"
                                 Executed="goBack_Excuted"
                                 LabelTitle="后退"
                                 ToolTipTitle="将所选标签贴在所选资源上"
                                 ToolTipDescription="在所选标签和所选资源自检建立联系，使其在所搜时可通过此联系找到对方."
                                 SmallImageSource="images/goBack.png"
                                 LargeImageSource="images/goBack.png" />

                <r:RibbonCommand x:Key="goForwardCommand"
                                 Executed="goForward_Excuted"
                                 LabelTitle="前进"
                                 ToolTipTitle="将所选标签贴在所选资源上"
                                 ToolTipDescription="在所选标签和所选资源自检建立联系，使其在所搜时可通过此联系找到对方."
                                 SmallImageSource="images/goForward.png"
                                 LargeImageSource="images/goForward.png" />

                <r:RibbonCommand x:Key="AddTagCommand"
                                 Executed="AddTag_Excuted"
                                 LabelTitle="添加标签"
                                 ToolTipTitle="为资源添加新的标签"
                                 ToolTipDescription="为资源添加新的标签（可以是您认为与当前资源有关的所有词条），如需删除可直接选中标签并按delete."
                                 SmallImageSource="images/AddNew.png"
                                 LargeImageSource="images/AddNew.png" />

                <r:RibbonCommand x:Key="ModifyTagCommand"
                                Executed="ModifyTag_Excuted"
                                LabelTitle="修改"
                                ToolTipTitle="修改标签"
                                ToolTipDescription="可以随时为标签改个新名字，如需删除可直接选中标签并按delete."
                                SmallImageSource="images/Delete.png"
                                LargeImageSource="images/Delete.png" />
                
                <r:RibbonCommand x:Key="AddTagAndSearchCommand"
                                 Executed="tagAddedAndSearchedExecuted"
                                 LabelTitle="添加查询"
                                 ToolTipTitle="添加标签再查询"
                                 ToolTipDescription="可以为资源添加标签，添加后直接根据所加标签进行查询"
                                 SmallImageSource="images/search.png"
                                 LargeImageSource="images/search.png" />


           

            </ResourceDictionary>
        </DockPanel.Resources>
        <r:Ribbon DockPanel.Dock="Top" Title="Moon 1.0 Beta"  >
            <r:Ribbon.Resources>
                <r:RibbonGroupSizeDefinitionCollection x:Key="RibbonLayout">
                    <r:RibbonGroupSizeDefinition>
                        <r:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True"/>
                        <r:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True"/>
                        <r:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True"/>
                    </r:RibbonGroupSizeDefinition>
                    <r:RibbonGroupSizeDefinition>
                        <r:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True"/>
                        <r:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="True"/>
                        <r:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="True"/>
                    </r:RibbonGroupSizeDefinition>
                    <r:RibbonGroupSizeDefinition>
                        <r:RibbonControlSizeDefinition ImageSize="Large" IsLabelVisible="True"/>
                        <r:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="False"/>
                        <r:RibbonControlSizeDefinition ImageSize="Small" IsLabelVisible="False"/>
                    </r:RibbonGroupSizeDefinition>
                    <r:RibbonGroupSizeDefinition IsCollapsed="True" />
                </r:RibbonGroupSizeDefinitionCollection>
            </r:Ribbon.Resources>
            <r:Ribbon.ApplicationMenu>
                <r:RibbonApplicationMenu>
                    <r:RibbonApplicationMenu.Command>
                        <r:RibbonCommand 
                 ToolTipTitle="Moon Resource Manager"   />
                        
                    </r:RibbonApplicationMenu.Command>
                </r:RibbonApplicationMenu>
            </r:Ribbon.ApplicationMenu>

            <r:RibbonTab Label="使用">
                <r:RibbonTab.Groups>
                    <r:RibbonGroup GroupSizeDefinitions="{StaticResource RibbonLayout}">
                        <r:RibbonGroup.Command>
                            <r:RibbonCommand LabelTitle="搜索方式" SmallImageSource="images/Paste.png" />
                        </r:RibbonGroup.Command>
                        <r:RibbonButton Command="{StaticResource SearchByTagCommand}"/>
                        <r:RibbonButton Command="{StaticResource SearchByResourceCommand}" Click="RibbonButton_Click" />
                    </r:RibbonGroup>
                    <r:RibbonGroup GroupSizeDefinitions="{StaticResource RibbonLayout}">
                        <r:RibbonGroup.Command>
                            <r:RibbonCommand LabelTitle="访问" SmallImageSource="images/Backup.png" />
                        </r:RibbonGroup.Command>
                        <r:RibbonButton Command="{StaticResource OpenResourceCommand}" />
                        
                    </r:RibbonGroup>
                    <r:RibbonGroup GroupSizeDefinitions="{StaticResource RibbonLayout}" HorizontalAlignment="Stretch">
                        <r:RibbonGroup.Command>
                            <r:RibbonCommand LabelTitle="修改" SmallImageSource="images/Backup.png" />
                        </r:RibbonGroup.Command>
                        <r:RibbonButton Command="{StaticResource CreateRelationCommand}"/>
                   
                    </r:RibbonGroup>
                    <r:RibbonGroup GroupSizeDefinitions="{StaticResource RibbonLayout}">
                        <r:RibbonGroup.Command>
                            <r:RibbonCommand LabelTitle="转到" SmallImageSource="images/Paste.png" />
                        </r:RibbonGroup.Command>
                        <r:RibbonButton Command="{StaticResource goBackCommand}" Name="goBack" IsEnabled="False"/>
                        <r:RibbonButton Command="{StaticResource goForwardCommand}" Click="RibbonButton_Click" Name="goForward" IsEnabled="False"/>
                    </r:RibbonGroup>
                   
                </r:RibbonTab.Groups>
            </r:RibbonTab>


        </r:Ribbon>
        
        <Grid>
        <Grid.RowDefinitions>
        </Grid.RowDefinitions>
        <Grid x:Name="Context" Grid.RowSpan="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="20*"/>
                <ColumnDefinition Width="1*"/>
                <ColumnDefinition Width="20*"/>
            </Grid.ColumnDefinitions>
            <Grid x:Name="ResourceGrid" RenderTransformOrigin="0.5,0.5">
                <Grid.RowDefinitions>
                        <RowDefinition Height="40"/>
                        <RowDefinition Height="*"/>

                </Grid.RowDefinitions>
                    <StackPanel Orientation="Horizontal" Grid.Row="0">
                        <Label  Content="资源:" VerticalAlignment="Center"/>
                    <Label Content="请将资源拖入本框" VerticalAlignment="Center" />
                    </StackPanel>
                    <ListBox x:Name="resourceList" Margin="3" BorderThickness="9" Grid.Row="1" AllowDrop="True" SelectionMode="Extended" KeyUp="resourceList_KeyUp" Background="Black" OpacityMask="Cyan" Foreground="AliceBlue" Opacity="0.5" 
                              MouseRightButtonUp="resourceList_MouseRightButtonUp"  MouseDoubleClick="resourceList_MouseDoubleClick" MouseLeftButtonUp="resourceList_MouseLeftButtonUp"
                              ItemsSource="{Binding}"
                             ToolTip="资源可以是文件或者网址，拖进来后，会按当前资源进行搜索。delete可以将资源从框中移走（不会真正删除）">
                        
                        <ListBox.Resources>
                            <me:ResourceItemIconConvertor x:Key="resourceiconConverter"/>
                        </ListBox.Resources>
                            <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Image Source="{Binding Resource.ResourceType,Converter = {StaticResource resourceiconConverter}}" Width="40" Height="30"/>
                                <TextBlock Text="{Binding Resource.ResourceName}"/>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                    </ListBox>
                    <Popup x:Name="popMenu" PopupAnimation="Slide" Width="80" Height="60" PlacementTarget="{Binding ElementName=selectedResource}" Placement="MousePoint" AllowsTransparency="True" StaysOpen="False" IsOpen="False">
                        <Border Background="#FFCFCFCF" CornerRadius="5" BorderBrush="#FF000000" BorderThickness="1">
                            <StackPanel Margin="3">
                                <TextBox Name="textOnPopmenu" Margin="5"/>
                                <Button Name="buttonOnPopmenu" Content="创建标签" Margin="3" Click="buttonOnPopmenu_Click"/>
                            </StackPanel>
                        </Border>
                    </Popup>
                </Grid>
            <GridSplitter Grid.Column="1"/>
            <Grid x:Name="TagGrid" RenderTransformOrigin="0.5,0.5" Grid.Column="2">
                <Grid.RowDefinitions>

                        <RowDefinition Height="40"/>
                        <RowDefinition Height="*"/>

                </Grid.RowDefinitions>
                
                    <StackPanel Orientation="Horizontal" Grid.Row="0"><Label HorizontalAlignment="Left" Margin="0,0,0,0" Content="标签:" VerticalAlignment="Center" d:LayoutOverrides="Height" Width="35" />
                        <TextBox FlowDirection="LeftToRight" HorizontalAlignment="Right" Name="tagName" VerticalAlignment="Center" Width="60" Margin="0" Height="26" />

                        <r:RibbonButton Command="{StaticResource AddTagCommand}" Height="40" Width="44" />
                        <r:RibbonButton Command="{StaticResource ModifyTagCommand}" Height="40" Width="44" />
                        <r:RibbonButton Command="{StaticResource AddTagAndSearchCommand}" Height="40" Width="44" />
                    </StackPanel>
                    <ListBox x:Name="tagList" Margin="3,3,3,3" BorderThickness="9" Grid.Row="1" SelectionMode="Extended"  KeyUp="tagList_KeyUp" Background="Black" Foreground="AliceBlue" OpacityMask="Cyan" Opacity="0.5" MouseDoubleClick="tagList_MouseDoubleClick" 
                              ItemsSource="{Binding}"
                             ToolTip="这里显示标签，属于左侧选中资源的标签前面是蓝色，否则是红色;圆为非游离标签，旗子为游离的标签，delete 可以真正删除非游离的标签 ">
                        <ListBox.Resources>
                            <me:ItemStateTokenConvertor x:Key="iconConverter"/>                             
                        </ListBox.Resources>
                        <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Image Source="{Binding State,Converter={StaticResource iconConverter}}" Width="40" Height="30"/>
                                <TextBlock Text="{Binding Tag.TagName}"/>
                            </StackPanel>                           
                        </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>

                </Grid>
        </Grid>
        </Grid>
    </DockPanel>
</r:RibbonWindow>
